package com.tzy.rabbitmq.workqueue;

import com.google.gson.Gson;
import com.rabbitmq.client.Channel;
import com.rabbitmq.client.Connection;
import com.tzy.rabbitmq.constant.RabbitmqConstant;
import com.tzy.rabbitmq.utils.RabbitmqUtil;

import java.io.IOException;
import java.util.concurrent.TimeoutException;

/**
 * @author 自律且自强ing
 */
public class OrderSystem {
    /**
     * 先获取连接,
     * 连接对象创建频道
     * 频道对象声明队列
     * @param args args
     * @throws IOException IO
     * @throws TimeoutException Timeout
     */
    public static void main(String[] args) throws IOException, TimeoutException {
        Connection connection = RabbitmqUtil.getConnection();
        Channel channel = connection.createChannel();
        channel.queueDeclare(RabbitmqConstant.QUEUE_SMS,false,false,false,null);
        for (int i = 0; i < 100; i++) {
            SMS sms = new SMS("乘客"+i,"16688888"+i,"您的车票已预订成功");
            String jsonSms = new Gson().toJson(sms);
            channel.basicPublish("",RabbitmqConstant.QUEUE_SMS,null,jsonSms.getBytes());
        }
        System.out.println("发送数据成功");
        channel.close();
        connection.close();
    }
}
